package com.panshi.modules.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.panshi.api.MemberApi;
import com.panshi.modules.service.MemberService;
import com.panshi.modules.service.UserService;
import com.panshi.vo.CodeMsgConstant;
import com.panshi.vo.R;
import com.panshi.vo.SearchVO;
import com.panshi.vo.StatusVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/member")
public class MemberController implements MemberApi {

    @Autowired
    private MemberService memberService;

    @Override
    @PostMapping("/pageMemberList")
    public R pageMemberList(@RequestBody SearchVO searchVO) {
        IPage page = memberService.pageMemberList(searchVO);
        if(page.getRecords() != null){
            return R.ok(CodeMsgConstant.CODE_0).data("data",page.getRecords()).data("count",page.getTotal()).data("code",0);
        }
        return R.error(CodeMsgConstant.CODE_1);
    }

    @Override
    @PutMapping("/edit/status")
    public R editMemberStatus(@RequestBody StatusVO statusVO) {
        int edit = memberService.editMemberStatus(statusVO);
        if(edit > 0){
            return R.ok(CodeMsgConstant.CODE_0);
        }
        return R.error(CodeMsgConstant.CODE_1);
    }
}
